﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace blackhouse.BlackApart.Data.Caching
{
    public class CachedPlaceData : IPlaceDataAccess
    {

        #region Fields

        private IPlaceDataAccess decoratedDataAccess;
        private NemoCache cache;

        #endregion

        #region Constructors

        public CachedPlaceData(IPlaceDataAccess decoratedDataAccess, string connectionStringToDecoretedDb)
        {
            this.decoratedDataAccess = decoratedDataAccess;
            this.cache = new NemoCache(TimeSpan.FromMinutes(2), connectionStringToDecoretedDb);
        }

        #endregion

        #region IPlaceDataAccess Members

        public PlaceData[] GetAllPlaces(string language)
        {
            cache.Reset();
            cache.SetDependencyTables("T222", "T216");
            cache.SetKey("GetAllPlaces");
			cache.SetParameters(language);
            PlaceData[] data = cache.GetData<PlaceData[]>();
            if (data == null)
            {
                data = this.decoratedDataAccess.GetAllPlaces(language);
                cache.SetCaching(data);
            }
            return data;
        }

        #endregion

    }
}
